<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="!!(limits.length >=1 && limits.filter(it => it.FName === '新增').length)"
          :is-edit-show="!!(limits.length >=1 && limits.filter(it => it.FName === '修改').length)"
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :lists="options"
          :is-settings-show = "lookSetShow"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @selectSettings="selectSettings"
      /></el-row>
      <br>

      <el-row class="common-row">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-input v-model="keyword" clearable style="width: 160px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>
          <el-select v-model="fstatus" clearable filterable style="width: 150px;" placeholder="请选择审核状态" @change="searchUser">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select>
          <!-- <el-select v-model="fchuanjishe" clearable filterable style="width: 140px;" placeholder="请选择船级类型" @change="searchUser">
            <el-option
              v-for="item in fchuanjisheList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select> -->
          <el-select v-model="fbrand" style="width: 120px;" clearable placeholder="请选择品牌" @change="searchUser">
            <el-option
              v-for="item in brandList"
              :key="item.finterid"
              :label="item.fname"
              :value="item.fname"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导入').length" type="primary" icon="el-icon-refresh" @click="exportTableData">导入 </el-button>

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="primary" icon="el-icon-my-export" @click="downData">导出</el-button>
        <el-button type="primary" icon="el-icon-my-updown" @click="handleDownload">下载{{ fmofanName }}模板</el-button>

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="primary" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="primary" icon="el-icon-close" @click="check('0')">反审</el-button>

        <el-button type="primary" icon="el-icon-mobile-phone" @click="vxeSendSms">发送信息</el-button>
        <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button>

      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      ref="bjTable"
      :data="tableData"
      :height="tableHeight"
      :summary-method="getSummaries"
      :header-cell-style="tableHeaderStyle"
      show-summary
      class="tableCss"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @cell-dblclick="cellDbClick"
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>

        </el-table-column>
      </template>
    </el-table>

    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑" width="30%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :inline="true" :model="form" label-width="150px" class="form1">

        <el-row >
          <el-col v-for="item in dialogThead" :span="24" :key="item.fid ">

            <el-form-item :label="item.frepcap" :prop="item.frepfld" >
              <template v-if="item.frepmeg == 1">
                <template v-for="base in baseList" v-if="base.name === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" :key="base.name" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in base[item.frepfld]"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>
              </template>
              <!-- 多文本-->
              <template v-else-if="item.frepmeg == 6" >
                <template >
                  <el-input :rows="3" v-model="form[item.frepfld]" type="textarea" />
                </template>
              </template>
              <!-- 日期框-->
              <template v-else-if="item.frepmeg == 4" >
                <template >
                  <el-date-picker v-model="form[item.frepfld]" style="width:100%" class="date_el" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" />
                </template>
              </template>
              <!-- 禁止编辑-->
              <template v-else-if="item.frepmeg == 5" >
                <template >
                  <el-input v-model="form[item.frepfld]" :disabled="editText"/>
                </template>
              </template>

              <!-- 输入框 -->
              <template v-else >
                <el-input v-model="form[item.frepfld]" clearable @dblclick.native="inputDbClick" />
              </template>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="dialog-footer">
          <el-form-item >
            <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
            <el-button @click="addUserModal=false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea" style="width:400px;"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 下载模板 -->
    <el-dialog :visible.sync="tableSetExcel" title="提示：信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="fmdDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="60%">
      <div >
        <div style="margin-bottom: 20px">
          <el-input
            v-model="fmdDetailSettings.fdetailKeyword"
            clearable
            placeholder="搜索"
            style="width: 160px;"
            @keyup.native.enter="searchFmd"
            @change="searchFmd" />
          <!-- <el-select v-model="fmdDetailSettings.fbrand" clearable placeholder="请选择品牌" @change="searchFmd">
            <el-option
              v-for="item in fmdDetailSettings.fbrandList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select v-model="fmdDetailSettings.fdanweibumen" clearable placeholder="请选择部门" @change="searchFmd">
            <el-option
              v-for="item in fmdDetailSettings.fdanweibumenList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select> -->
          <el-button type="primary" @click="searchFmd">搜索</el-button>
          <el-button type="primary" @click="fmdConfirm">确认</el-button>
        </div>
        <el-table
          v-loading="fmdDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="fmdTable"
          :data="fmdDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row
          @selection-change="fmdHandleSelectionChange">
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in fmdDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>
              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="fmdDetailSettings.total"
          :page-sizes="fmdDetailSettings.pagesizes"
          :page-size="fmdDetailSettings.pagesize"
          :current-page.sync="fmdDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="fmdHandleSizeChange"
          @current-change="fmdHandleCurrentChange"/>
      </div>
    </el-dialog>

    <!-- 导入 -->
    <el-dialog
      v-el-drag-dialog
      :title="importGrid.title"
      :visible.sync="importGrid.fmodal"
      :close-on-click-modal="false"
      :show-close="true"
      class="import-set-modal"
      width="78%"
      @close="closeImportDialog">
      <div class="search-grid" style="margin-bottom: 20px;">
        <!-- <vxe-button status="success" icon="vxe-icon-add" content="新增" @click="importGridAdd"/> -->
        <vxe-button status="success" icon="vxe-icon-save" content="保存" @click="importGridSave"/>
        <vxe-button class="import-excel" status="primary" content="导入Excel" @click="toImport" />
        <vxe-button status="success" icon="vxe-icon-delete" content="删除" @click="importGridDel"/>
        <ExcelImport
          :ref="importGrid.excelRefs"
          :data-row="importGrid.dataRow"
          :value-match="importGrid.fieldArr"
          :accept="importGrid.accept"
          @changeExcel="uploadExamFile" />
      </div>
      <vxe-grid
        :class="importGrid.class"
        :id="importGrid.id"
        :ref="importGrid.gridRefs"
        :print-config="{}"
        :import-config="{}"
        :export-config="{}"
        :columns="importGrid.columns"
        :toolbar-config="importGrid.tableToolbar"
        :data="importGrid.data"
        :custom-config="{storage: true}"
        :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
        align="center"
        height="450"
        border
        resizable
        keep-source>

        <template #fmodel_edit="{row}">
          <vxe-input v-model="row.fmodel" />
        </template>

        <template #fchuanjishe_edit="{row}">
          <vxe-input v-model="row.fchuanjishe" />
        </template>
        <template #fzjjianyanf_edit="{row}">
          <vxe-input v-model="row.fzjjianyanf" />
        </template>
        <template #fnoxpaifangf_edit="{row}">
          <vxe-input v-model="row.fnoxpaifangf" />
        </template>
        <template #flvtuf_edit="{row}">
          <vxe-input v-model="row.flvtuf" />
        </template>
        <template #fjizuojijiaf_edit="{row}">
          <vxe-input v-model="row.fjizuojijiaf" />
        </template>
        <template #fzhusuf_edit="{row}">
          <vxe-input v-model="row.fzhusuf" />
        </template>
        <template #fjiaotongf_edit="{row}">
          <vxe-input v-model="row.fjiaotongf" />
        </template>
        <template #ftongxunf_edit="{row}">
          <vxe-input v-model="row.ftongxunf" />
        </template>
        <template #fzhengshuf_edit="{row}">
          <vxe-input v-model="row.fzhengshuf" />
        </template>
        <template #fpaifangtestf_edit="{row}">
          <vxe-input v-model="row.fpaifangtestf" />
        </template>
      </vxe-grid>
    </el-dialog>

    <!-- SendMsg弹窗 -->
    <SendMsg
      :send-msg-info="sendMsgDialog"
      @confirmSendMsg="confirmSendMsg" />

    <!-- 机型明细 -->
    <FmodelDetail
      :fmodel-dialog="fmodelDialog"
      @handleSelectionChange="fmodelSelectionChange"
      @downData="fmodelDownData"
      @handleSizeChange="fmodelSizeChange"
      @handleCurrentChange="fmodelCurrentChange" />

  </div>
</template>
<script>
let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn, checkStatus, getCSData } from '../../api/salary'
import { brand } from '../../mixins/brand'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, downFileUrl } from '../../api/account'
import { FImportGEN, genAdd, genDel, genList, FBMluruMx } from '../../api/gen'
import { sendsms, beijianTree } from '../../api/peijian'
import '../../styles/common.scss'
import '../../styles/svg.scss'

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination, brand],
  data() {
    return {
      sendMsgDialog: {
        width: '50%',
        title: '发送信息',
        sendMsgLoading: false,
        dialogSendMsgModal: false,
        loadingFormSendMsg: false,
        userList: [],
        sendUsrList: [],
        formSendMsg: {},
        rulesSendMsg: {},
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      },

      importGrid: {
        class: 'import-set-modal',
        rows: '',
        fmodel: '',
        fbrand: '',
        title: '船检费CCS（导入）',
        excelRefs: 'importExcel', // ExcelImport
        dataRow: 0, // 数据开始行 默认从第0行开始
        fieldCap: [
          { field: 'fmodel', frecap: '主机型号' },
          { field: 'fchuanjishe', frecap: '船级社' },
          { field: 'fzjjianyanf', frecap: '整机检验费' },
          { field: 'fnoxpaifangf', frecap: 'NOX排放费' },
          { field: 'flvtuf', frecap: '旅途时间费用' },
          { field: 'fjizuojijiaf', frecap: '机座、机架过程检验费用' },
          { field: 'fzhusuf', frecap: '住宿费用' },
          { field: 'fjiaotongf', frecap: '交通费用' },
          { field: 'ftongxunf', frecap: '通讯费用' },
          { field: 'fzhengshuf', frecap: '证书费' },
          { field: 'fpaifangtestf', frecap: '排放测试费用' }
        ],
        fieldArr: [], // 数据列 必须与excel中的表列顺序相对应
        valueTitle: [], // frecap
        accept: '.xls,.xlsx',
        id: 'import-grid',
        gridRefs: 'importTable', // vxe-grid
        fmodal: false,
        data: [],
        columns: [
          { type: 'checkbox', width: 50 },
          { type: 'seq', width: 60 }
        ]
      },

      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: '',
      fmofanName: '',

      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],

      baseListA: [
        {
          'finterid': 0,
          'fname': 'CCS'
        }
        // {
        //   'finterid': 1,
        //   'fname': 'ABS'
        // },
        // {
        //   'finterid': 2,
        //   'fname': 'LR'
        // },
        // {
        //   'finterid': 3,
        //   'fname': 'DNV'
        // },
        // {
        //   'finterid': 4,
        //   'fname': 'BV'
        // }

      ],
      baseList: [],
      upDataBasic: {},

      // 型号
      fmdDetailSettings: {
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: '',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1,
        FRepKey: 14007,
        multipleSelection: [],
        fmodelId: ''
      },

      detail: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false,
      oriColumnData: [],
      setConfigData: [],
      fchuanjishe: '',
      fchuanjisheList: [
        {
          value: 'CCS',
          label: 'CCS'
        },
        {
          value: 'ABS',
          label: 'ABS'
        },
        {
          value: 'LR',
          label: 'LR'
        },
        {
          value: 'DNV',
          label: 'DNV'
        },
        {
          value: 'BV',
          label: 'BV'
        }
      ],

      opername: '',

      fmodelDialog: {
        fmodel: '',
        fdetailModal: false,
        // 批量删除
        checkData: [],
        selectedData: [],
        // 表头、表格设置
        tableData: [],
        tableList: [],
        defaultFormThead: [],
        formThead: [],
        dialogThead: [],
        curData: {},
        listLoading: false,
        // 分页相关变量
        total: 0,
        currentPage: 1,
        // pagesize: 100,
        pagesize: 20,
        pagesizes: [10, 20, 50, 100, 300, 500, 1000, 2000, 3000, 5000, 10000],
        // 导出相关
        header: [],
        headerKeys: [],
        listData: []
      }
    }
  },
  async mounted() {
    await this.getColumns()

    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    this.baseList.push({ name: 'fchuanjishe', 'fchuanjishe': this.baseListA })
    await this.getAllData()
    // 参数
    this.getCSData()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }

    // 参数设置
    const setConfigData = JSON.parse(localStorage.getItem('setConfigData'))
    this.$set(this, 'setConfigData', setConfigData)
  },
  methods: {
    async vxeSendSms() {
      // console.log(this.selectedData, ' this.selectedData')
      if (this.selectedData && this.selectedData.length) {
        this.sendMsgDialog.dialogSendMsgModal = true
        await this.getBeijianTree()
      } else {
        this.$message({
          message: '请选中一行信息',
          type: 'error'
        })
      }
    },
    async confirmSendMsg(selectMsgArr) {
      this.sendMsgDialog.dialogSendMsgModal = true
      try {
        const fcontent = this.sendMsgDialog.formSendMsg.fcontent
        const fbillno = this.selectedData[0].fbillno
        if (selectMsgArr.length) {
          const fid = selectMsgArr.join(',')
          if (!fid) {
            this.$message({
              message: '手机号为空',
              type: 'error'
            })
            return
          }

          const res = await sendsms({
            opername: decodeURIComponent(this.globalDb.fname),
            fid,
            fcontent,
            fbillno
          })
          // console.log(res, ' res')
          if (res.Error === 0) {
            this.sendMsgDialog.formSendMsg.fcontent = ''
            this.sendMsgDialog.dialogSendMsgModal = false
            this.selectedData.length = 0
            this.$refs.bjTable.clearSelection()
          }
        } else {
          this.$message({
            message: '未选中发送信息通知人员',
            type: 'error'
          })
          return
        }
      } catch (error) {
        this.sendMsgDialog.dialogSendMsgModal = false
      }
    },
    async getBeijianTree() {
      try {
        this.sendMsgDialog.sendMsgLoading = true
        const res = await beijianTree({
          opername: decodeURIComponent(this.globalDb.fname)
        })
        // console.log(res, ' res')

        this.sendMsgDialog.sendUsrList = res.Data
        this.sendMsgDialog.sendMsgLoading = false
      } catch (error) {
        this.sendMsgDialog.sendMsgLoading = false
        console.log(error)
      }
    },

    getColumns() {
      this.importGrid.fieldCap.map(item => {
        this.importGrid.fieldArr.push(item.field)
        this.importGrid.valueTitle.push(item.frecap)
        this.importGrid.columns.push({
          field: item.field,
          title: item.frecap,
          editRender: {},
          slots: { edit: item.field + '_edit' }
        })
      })
    },
    exportTableData() {
      this.importGrid.fmodal = true
      this.importGridDel()
    },
    // 获取数据
    uploadExamFile(data) {
      console.log('导出的数据', data)
      this.importGrid.data = data
    },
    importData() {
      this.importGrid.fmodal = true
      this.importGridDel()
    },
    toImport() {
      this.$refs[this.importGrid.excelRefs].open()
    },
    importGridAdd() { // 新增
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.insertAt(-1, -1)
    },
    importGridDel() { // 删除当前行
      const $grid = this.$refs[this.importGrid.gridRefs]
      if ($grid) {
        const checkData = $grid.getCheckboxRecords()
        if (checkData.length) {
          $grid.removeCheckboxRow()
        } else {
          this.importGrid.data = []
          $grid.remove($grid.getCheckboxRecords())
        }
      }
    },
    async importGridSave() { // 保存
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.getRecordset()
      const { fullData } = $grid.getTableData()
      // console.log(tableData, ' importGridSave tableData')
      try {
        const res = await FImportGEN({
          FRepKey,
          // fbillno: this.importGrid.fbillno,
          // rows: this.importGrid.rows,
          opername: this.opername,
          // fmodel: this.importGrid.fmodel,
          // fbrand: this.importGrid.fbrand,
          data: fullData
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          this.importGrid.rows = ''
          this.importGrid.fbillno = ''
          this.importGrid.fmodel = ''
          this.importGrid.fbrand = ''
          this.importGridDel()
          this.importGrid.fmodal = false
          await this.getAllData()
          // console.log(this.importGrid, ' this.importGrid')
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    closeImportDialog() {
      this.importGrid.rows = ''
      this.importGrid.fbillno = ''
      this.importGrid.fmodel = ''
      this.importGrid.fbrand = ''
      this.importGridDel()
    },
    // 导入数据上面----------------

    async inputDbClick() {
      console.log(this.form, ' this.form  inputDbClick')
      this.fmdDetailSettings.fdetailModal = true
      this.fmdDetailSettings.fdetailKeyword = this.form.fmodel
      // 弹窗数据
      await this.getFmdBodyData()
      await this.getFmdHeadData()
    },
    async searchFmd() {
      await this.getFmdBodyData()
      await this.getFmdHeadData()
    },
    async fmdHandleSizeChange(val) {
      this.fmdDetailSettings.currentPage = 1
      this.fmdDetailSettings.pagesize = val
      await this.getFmdBodyData()
      await this.getFmdHeadData()
    },
    async fmdHandleCurrentChange(val) {
      this.fmdDetailSettings.currentPage = val
      await this.getFmdBodyData()
      await this.getFmdHeadData()
    },
    // 表头数据
    async getFmdHeadData() {
      try {
        this.fmdDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername: this.opername,
          FRepKey: this.fmdDetailSettings.FRepKey
        })
        this.fmdDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.fmdDetailSettings.detailFormThead = res.Data
          } else {
            this.fmdDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.fmdDetailSettings.detailFormThead.map(item => {
          this.fmdDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.fmdDetailSettings.fdetailData = this.fmdDetailSettings.fdetailList.slice()
        // 获取显示表头键值对
        this.fmdDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.fmdDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })
        // console.log(this.fmdDetailSettings.detailFormThead, ' this.fmdDetailSettings.detailFormThead')
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })
        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.fmdDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getFmdBodyData() {
      try {
        this.fmdDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername: this.opername,
          keyword: this.fmdDetailSettings.fdetailKeyword,
          fstatus: '',
          limit: this.fmdDetailSettings.pagesize,
          page: this.fmdDetailSettings.currentPage,
          FRepKey: this.fmdDetailSettings.FRepKey
        })
        this.fmdDetailSettings.fdetailLoading = false
        this.fmdDetailSettings.fdetailList = res.Data
        this.fmdDetailSettings.total = res.total
      } catch (error) {
        this.fmdDetailSettings.fdetailLoading = false
      }
    },
    closeDialog() {
      this.$refs.fmdTable.clearSelection()
    },
    fmdConfirm() {
      console.log(this.form, ' this.form')
      const selected = this.fmdDetailSettings.multipleSelection
      if (!selected.length) {
        this.$message({
          message: '请选中一行',
          type: 'warning'
        })
        return
      }
      this.$set(this.form, 'fmodel', selected[0].fmodel)
      this.fmdDetailSettings.fdetailModal = false
      this.$refs.fmdTable.clearSelection()
      this.fmdDetailSettings.multipleSelection = []
    },
    fmdHandleSelectionChange(val) {
      if (val.length) {
        this.fmdDetailSettings.multipleSelection = val
      } else {
        this.fmdDetailSettings.multipleSelection = []
      }
      if (val.length > 1) {
        this.$refs.fmdTable.clearSelection()
        this.$refs.fmdTable.toggleRowSelection(val.pop())
      }
    },
    async getCSData() {
      try {
        // FSetLoginName
        const res = await getCSData({ opername: decodeURIComponent(this.globalDb.fname), fcategory: 'IB', fkey: '', db: this.globalDb.db })
        if (res.Data) {
          this.loginTitleName = res.Data.fsetloginname
          localStorage.setItem('setConfigData', JSON.stringify(res.Data))
        }
      } catch (error) {
        console.log(error)
      }
    },

    // 刷新
    refresh() {
      window.location.reload()
    },

    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // -----------------上传开始---------------------
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUpload() {
      this.$refs.upload.submit()
    },

    handleRemove(file, fileList) {

    },
    handlePreview(file) {

    },
    exceed() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },
    notice(e) {
      if (e.code === 200) {
        this.$message(e.message)
      } else {
        this.$message(e.message)
      }
    },
    // -----------------上传结束---------------------
    // 表头数据
    async getAllHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()
        let tableTemp
        if (this.selectedData.length) {
          tableTemp = this.selectedData
        } else {
          tableTemp = this.tableList.slice()
        }

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getAllBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          fbrand: this.fbrand,
          fchuanjishe: this.fchuanjishe,
          fstatus: this.fstatus,
          limit: this.total,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    // 导出数据
    async downData() {
      await this.getAllBodyData()
      await this.getAllHeadData()
      await this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    // 设置表格字段--获取数据
    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })

        this.configList = res.Data

        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          fbrand: this.fbrand,
          fchuanjishe: this.fchuanjishe,
          fstatus: this.fstatus,
          limit: this.pagesize,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },

    async searchUser() {
      await this.getAllData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      await this.getAllData()
    },
    salaryCurrentChange(val) {
      this.curData = val
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername,
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    // -----------------上传模板开始---------------------
    beforeAvatarUploadBasic(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUploadBasic() {
      this.$refs.uploadBasic.submit()
    },

    handleRemoveBasic(file, fileList) {

    },
    handlePreviewBasic(file) {

    },
    exceedBasic() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },

    noticeBasic(e) {
      if (e.Error === 0) {
        this.$message(e.Message)
        this.getAllData()
        this.$refs.uploadBasic.clearFiles()
      } else {
        this.$message(e.Message)
      }
    },
    // 添加
    async addUser() {
      this.editText = false
      this.form = {}
      const data = {}
      this.dialogThead.map(item => { data[item.frepfld] = '' })
      for (const i in data) {
        this.$set(this.form, i, data[i])
      }
      this.$set(this.form, 'fchuanjishe', 'CSS')

      this.form.fzzfax = this.setConfigData.fsetfzzfax
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })

      this.addUserModal = true
    },

    // 修改
    async editUser() {
      const data = this.selectedData[0]

      if (data && Number(data.fstatus) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'error'
        })
        return
      }
      this.editText = true
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      this.dialogThead.map(item => { this.$set(this.form, item.frepfld, '') })
      this.form.fid = 0
      this.addUserModal = true
      for (const i in this.form) {
        this.form[i] = data[i]
        this.dialogThead.map(item => {
          if (item.frepmeg === 1 && i === item.frepfld && !data[i]) {
            this.form[i] = ''
          }
        })
      }

      if (typeof (this.form.fzzfax) === 'undefined') {
        this.$set(this.form, 'fzzfax', data['fzzfax'])
      }
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })
    },

    async confirm() {
      console.log(this.setConfigData)
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            this.form.db = this.globalDb.db
            this.form.opername = opername
            this.form.FRepKey = FRepKey
            this.form.fzzfax = this.setConfigData.fsetfzzfax

            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })

              await this.getAllData()
            } else {
              this.loadingForm = false

              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
          }
        } else {
          return false
        }
      })
    },

    async delUser() {
      const data = this.checkData
      if (data.length < 1) {
        this.$message({
          message: '请选中要删除的一行',
          type: 'warning'
        })
        return
      }
      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const fid = data.join(',')
        const res = await genDel({
          db: this.globalDb.db,
          opername,
          data: this.selectedData,
          fid: fid,
          FRepKey

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 合计

    // 合计
    getSummaries({ columns, data }) {
      const sums = []
      const arr = []
      this.oriColumnData.forEach((item, itemIndex) => {
        if (item.frepfld && item.frepsum === 1) {
          arr.push(item.frepfld)
        }
      })
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums[columnIndex] = '合计'
        } else {
          if (arr.indexOf(column.property) >= 0) {
            sums[columnIndex] = this.sumNum(data, column.property).toFixed(2)
          } else {
            sums[columnIndex] = ''
          }
        }
      })
      // 返回一个二维数组的表尾合计
      return sums
    },

    sumNum(list, field) { // DONE
      let count = 0
      list.forEach(item => {
        count += Number(item[field]) * 100
      })
      return (count / 100)
    },

    // 1—审核，0—反审
    async check(Fstatus) {
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—审核，0—反审
              fid: this.checkData.join(',')

            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            fid: this.checkData.join(','),
            appname: ''
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },

    handleSelectionChange(val) {
      this.checkData = []
      this.selectedData = val
      val.map(it => {
        this.checkData.push(it.fid)
      })
    },

    fmodelSelectionChange(val) {
      this.fmodelDialog.selectedData = val
    },
    async cellDbClick(row, column, cell, event) {
      // console.log(column.id, column.property, column, row, event, 'column')
      if (column.property === 'fmodel') {
        this.fmodelDialog.fdetailModal = true
        this.fmodelDialog.fmodel = row.fmodel
        await this.getFBumenMX()
        await this.getFBumenMXHeader()
      }
    },
    // FBumenMX
    // 获取机型明细数据
    async getFBumenMX() {
      try {
        this.fmodelDialog.listLoading = true
        // const res = await genList({
        const res = await FBMluruMx({
          db: this.globalDb.db,
          FRepKey,
          opername,
          fmodel: this.fmodelDialog.fmodel,
          // keyword: '',
          // fstatus: this.fstatus,
          limit: this.fmodelDialog.pagesize,
          page: this.fmodelDialog.currentPage
          // fbrand: this.fbrand
        })
        this.fmodelDialog.listLoading = false
        this.fmodelDialog.tableList = res.Data
        this.fmodelDialog.total = res.total
      } catch (error) {
        this.fmodelDialog.listLoading = false
      }
    },
    // 表头数据
    async getFBumenMXHeader() {
      try {
        this.fmodelDialog.listLoading = true
        this.fmodelDialog.header = []
        this.fmodelDialog.headerKeys = []
        this.fmodelDialog.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.fmodelDialog.listLoading = false
        this.fmodelDialog.formThead = res.Data
        // this.oriColumnData = res.Data
        this.fmodelDialog.formThead.map(item => {
          this.fmodelDialog.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.fmodelDialog.tableData = this.fmodelDialog.tableList.slice()
        // 获取显示表头键值对
        this.fmodelDialog.formThead.filter(item => {
          if (!item.frephide) {
            this.fmodelDialog.header.push(item.frepcap)
            this.fmodelDialog.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.fmodelDialog.tableList.slice()
        // const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.fmodelDialog.listData[index] = {}
          this.fmodelDialog.headerKeys.map(it => {
            this.fmodelDialog.listData[index][it] = item[it]
          })
        })
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })
        this.fmodelDialog.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.fmodelDialog.listLoading = false
      }
    },
    async getFBumenMXHeaderAll() {
      try {
        this.fmodelDialog.listLoading = true
        this.fmodelDialog.header = []
        this.fmodelDialog.headerKeys = []
        this.fmodelDialog.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.fmodelDialog.listLoading = false
        this.fmodelDialog.formThead = res.Data
        // this.oriColumnData = res.Data
        // this.tableList = []
        this.fmodelDialog.formThead.map(item => {
          this.fmodelDialog.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.fmodelDialog.tableData = this.fmodelDialog.tableList.slice()
        // console.log(this.fmodelDialog.tableList, ' this.fmodelDialog.tableList')
        // console.log(this.fmodelDialog.tableData, ' this.fmodelDialog.tableData')
        let tableTemp
        if (this.fmodelDialog.selectedData.length) {
          tableTemp = this.fmodelDialog.selectedData
        } else {
          tableTemp = this.fmodelDialog.tableList.slice()
        }
        console.log(tableTemp, ' tableTemp')
        // 获取显示表头键值对
        this.fmodelDialog.formThead.filter(item => {
          if (!item.frephide) {
            this.fmodelDialog.header.push(item.frepcap)
            this.fmodelDialog.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.fmodelDialog.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.fmodelDialog.listData[index] = {}
          this.fmodelDialog.headerKeys.map(it => {
            this.fmodelDialog.listData[index][it] = item[it]
          })
        })
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })
        this.fmodelDialog.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.fmodelDialog.listLoading = false
      }
    },
    async fmodelSizeChange(val) {
      this.fmodelDialog.currentPage = 1
      this.fmodelDialog.pagesize = val
      await this.getFBumenMX()
      await this.getFBumenMXHeader()
    },
    async fmodelCurrentChange(val) {
      this.fmodelDialog.currentPage = val
      await this.getFBumenMX()
      await this.getFBumenMXHeader()
    },
    // 导出数据
    async fmodelDownData() {
      await this.getFBumenMX()
      await this.getFBumenMXHeaderAll()
      this.header = this.fmodelDialog.header
      this.headerKeys = this.fmodelDialog.headerKeys
      this.listData = this.fmodelDialog.listData
      await this.exportDetailData('机型明细')
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
.cb-set-modal ::v-deep .single-select-table thead .el-table-column--selection .cell {
  display: none;
}
.cb-set-modal ::v-deep .el-dialog__body {
  min-height: 350px!important;
  overflow: scroll;
  padding: 0 20px;
}
.import-set-modal ::v-deep .el-dialog__body {
  padding: 0 20px;
}
</style>
